#pragma once

#include "stdafx.h"


DWORD dwTlsIndex;
BSTR errorString;

void SetLastErrorString(BSTR strFormat, ...)
{
	


	if (dwTlsIndex == 0)
	{
		dwTlsIndex = TlsAlloc();
		if (TLS_OUT_OF_INDEXES == dwTlsIndex)
		{
			OutputDebugStringW(L"TlsAlloc fail!");
			return;
		}
	}
	
	va_list argList;
	va_start( argList, strFormat );
	CAtlStringW strTmp;
	strTmp.FormatV(strFormat, argList);

	va_end(argList);

	SysFreeString(errorString);
	errorString = SysAllocString(strTmp.GetString());
	
	TlsSetValue(dwTlsIndex, (VOID *)errorString);
	
}

const BSTR& GetLastErrorString()
{
	return errorString;
}